package com.example.cs4.controller;

import com.example.cs4.service.MessageRankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.data.redis.core.ZSetOperations;

@RestController
@RequestMapping("/api/Rank")
@Api(tags = "排行榜服务")
public class RankController {
    @Autowired
    private MessageRankService messageRankService;

    @GetMapping("/topUsers")
    @ApiOperation(value = "获取排名前10的用户")
    public List<String> getTopUsers(@RequestParam int count) {
        Set<ZSetOperations.TypedTuple<String>> topUsers = messageRankService.getTopUsers();
        return topUsers.stream()
                .limit(count)
                .map(ZSetOperations.TypedTuple::getValue)
                .collect(Collectors.toList());
    }
}